{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2d006641",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-06-28T03:51:54.046513Z",
     "start_time": "2021-06-28T03:51:53.837502Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4;5;2;5;0;1;0;9;2;0;7;9;2;G.all_edges=[[4, 5, 3, 7], [2, 3], [1, 5, 6, 9], [0, 1], [0], [0, 2, 9], [2], [0, 8], [7, 9], [5, 8, 2]]\n",
      "Before Sorted: G= [\n",
      "*V0:    colorcode=0\n",
      "   |--->4\n",
      "   |--->5\n",
      "   |--->3\n",
      "   |--->7\n",
      "   :4 edge(s), \n",
      "*V1:    colorcode=0\n",
      "   |--->2\n",
      "   |--->3\n",
      "   :2 edge(s), \n",
      "*V2:    colorcode=0\n",
      "   |--->1\n",
      "   |--->5\n",
      "   |--->6\n",
      "   |--->9\n",
      "   :4 edge(s), \n",
      "*V3:    colorcode=0\n",
      "   |--->0\n",
      "   |--->1\n",
      "   :2 edge(s), \n",
      "*V4:    colorcode=0\n",
      "   |--->0\n",
      "   :1 edge(s), \n",
      "*V5:    colorcode=0\n",
      "   |--->0\n",
      "   |--->2\n",
      "   |--->9\n",
      "   :3 edge(s), \n",
      "*V6:    colorcode=0\n",
      "   |--->2\n",
      "   :1 edge(s), \n",
      "*V7:    colorcode=0\n",
      "   |--->0\n",
      "   |--->8\n",
      "   :2 edge(s), \n",
      "*V8:    colorcode=0\n",
      "   |--->7\n",
      "   |--->9\n",
      "   :2 edge(s), \n",
      "*V9:    colorcode=0\n",
      "   |--->5\n",
      "   |--->8\n",
      "   |--->2\n",
      "   :3 edge(s)]\n",
      "lengths=[4, 2, 4, 2, 1, 3, 1, 2, 2, 3]\n",
      "[0, 2, 4, 2, 1, 3, 1, 2, 2, 3]\n",
      "[0, 2, 0, 2, 1, 3, 1, 2, 2, 3]\n",
      "[0, 2, 0, 2, 1, 0, 1, 2, 2, 3]\n",
      "[0, 2, 0, 2, 1, 0, 1, 2, 2, 0]\n",
      "[0, 0, 0, 2, 1, 0, 1, 2, 2, 0]\n",
      "[0, 0, 0, 0, 1, 0, 1, 2, 2, 0]\n",
      "[0, 0, 0, 0, 1, 0, 1, 0, 2, 0]\n",
      "[0, 0, 0, 0, 1, 0, 1, 0, 0, 0]\n",
      "[0, 0, 0, 0, 0, 0, 1, 0, 0, 0]\n",
      "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n",
      "********************\n",
      "Length Equal: [\n",
      "*V0:    colorcode=0\n",
      "   |--->4\n",
      "   |--->5\n",
      "   |--->3\n",
      "   |--->7\n",
      "   :4 edge(s), \n",
      "*V2:    colorcode=0\n",
      "   |--->1\n",
      "   |--->5\n",
      "   |--->6\n",
      "   |--->9\n",
      "   :4 edge(s), \n",
      "*V5:    colorcode=0\n",
      "   |--->0\n",
      "   |--->2\n",
      "   |--->9\n",
      "   :3 edge(s), \n",
      "*V9:    colorcode=0\n",
      "   |--->5\n",
      "   |--->8\n",
      "   |--->2\n",
      "   :3 edge(s), \n",
      "*V1:    colorcode=0\n",
      "   |--->2\n",
      "   |--->3\n",
      "   :2 edge(s), \n",
      "*V3:    colorcode=0\n",
      "   |--->0\n",
      "   |--->1\n",
      "   :2 edge(s), \n",
      "*V7:    colorcode=0\n",
      "   |--->0\n",
      "   |--->8\n",
      "   :2 edge(s), \n",
      "*V8:    colorcode=0\n",
      "   |--->7\n",
      "   |--->9\n",
      "   :2 edge(s), \n",
      "*V4:    colorcode=0\n",
      "   |--->0\n",
      "   :1 edge(s), \n",
      "*V6:    colorcode=0\n",
      "   |--->2\n",
      "   :1 edge(s)]\n",
      "G.all_edges=[[4, 5, 3, 7], [1, 5, 6, 9], [0, 2, 9], [5, 8, 2], [2, 3], [0, 1], [0, 8], [7, 9], [0], [2]]\n",
      "\n",
      "\n",
      "Gcount=10\n",
      "G.all_edges=[[4, 5, 3, 7], [1, 5, 6, 9], [0, 2, 9], [5, 8, 2], [2, 3], [0, 1], [0, 8], [7, 9], [0], [2]]|||G.all_colors=[2, 2, 3, 2, 0, 3, 3, 1, 1, 4]\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "clear1() missing 1 required positional argument: 'clrs_list'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m--------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                          Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-15-d59b196d1c0f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m     54\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0m__name__\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'__main__'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     55\u001b[0m         \u001b[0;31m#cProfile.runctx('main(20, 3)', None, locals())\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 56\u001b[0;31m         \u001b[0mmain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margv\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m<ipython-input-15-d59b196d1c0f>\u001b[0m in \u001b[0;36mmain\u001b[0;34m(maxVnum, maxDegNum, mode)\u001b[0m\n\u001b[1;32m     37\u001b[0m                 \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mG\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     38\u001b[0m         \u001b[0;31m#Draw\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 39\u001b[0;31m         \u001b[0mdealt_pairs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdealt_colors\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclear1\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mG\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     40\u001b[0m         \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"{G.all_edges=}\\n\\n {dealt_pairs=}\\n\\n {G.all_colors=}\\n\\n{dealt_colors=}\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     41\u001b[0m         \u001b[0mGnx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGraph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mTypeError\u001b[0m: clear1() missing 1 required positional argument: 'clrs_list'"
     ]
    }
   ],
   "source": [
    "\n",
    "from networkx.algorithms.centrality import degree_alg\n",
    "from algorithm.DataConverter import clear1\n",
    "from algorithm.Graph_gen import RandGenAdj\n",
    "from algorithm.Painter import *\n",
    "from collections import abc\n",
    "from Graphy import GraphByVertex, Vertex\n",
    "from numpy import random as rand\n",
    "from memory_profiler import *\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import cProfile\n",
    "import networkx as nx\n",
    "import numpy as np\n",
    "import sys\n",
    "\n",
    "\"\"\"\n",
    "现在已经有了一个随机生成连接情况的图\n",
    "下一步是上色。\n",
    "最后可视化就再说了吧。\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "color_list = ['r', 'lightcyan', 'cyan', 'c', 'teal']#Enumeration...\n",
    "\n",
    "#@profile\n",
    "def main(maxVnum, maxDegNum, mode='not print'):\n",
    "\n",
    "\t#Generate Graph\n",
    "\tG = RandGenAdj(maxVnum, maxDegNum)\n",
    "\t#Paint the Graph\n",
    "\tnearFilltry(G)\n",
    "\tGcount = G.count(by='v')\n",
    "\tprint(f\"{Gcount=}\")\n",
    "\tprint(f\"{G.all_edges=}|||{G.all_colors=}\")\n",
    "\tif mode == 'print':\n",
    "\t\tprint(G)\n",
    "\t#Draw\n",
    "\tdealt_pairs, dealt_colors = clear1(G)\n",
    "\tprint(f\"{G.all_edges=}\\n\\n {dealt_pairs=}\\n\\n {G.all_colors=}\\n\\n{dealt_colors=}\")\n",
    "\tGnx = nx.Graph()\n",
    "\tGnx.add_edges_from(dealt_pairs)#传入无向图库\n",
    "\tprint(Gnx.nodes)\n",
    "\tfor idx, clr in zip(Gnx.nodes, dealt_colors):\n",
    "\t\tprint(f\"{idx}=>{clr}\")\n",
    "\t\tprint(f\"{idx}=>{G[idx].get_color=} (in Graph)\")\n",
    "\t#colors = [color_list[clr_code] for clr_code in dealt_colors]\n",
    "\tnx.draw_networkx(Gnx, node_color=dealt_colors)\n",
    "\tplt.show()\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "\t#cProfile.runctx('main(20, 3)', None, locals())\n",
    "\tmain(10, 3, sys.argv[1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "854841d8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": true,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
